$(function() {

  $(".form").getFormTwo({
    // id: id
  }, function(data) {
    // getFilePhoto(data.imgPath);
  })

  $('.whiteboard').remove();

  //提交
  $("body").on("click", "#save-btn", function(event) {
    event.preventDefault();
    var success = $('.form').validate('submitValidate');
    if (success) {
      //验证通过提交表单
      submitFom();
    }
  })

});

// 下载图片
function getFilePhoto(filePath) {
  var imgUrl = site.apiUrl + '/file/downLoadPhotos?path=' + filePath;
  $("#imgPath .upload-state-done img").attr("src", imgUrl);
}

/*
 * 提交表单
 */
function submitFom() {
  var imgPath = $("#imgPath .upload-state-done").find("input[type=hidden]").val();
  var primaryNote = $("#primaryNote").val();

  var url = site.apiUrl + "/homePageSetting/addAddressSetting";
  var thisId = $("#currentId").val();
  var obj = {
    'id': thisId,
    'imgPath': imgPath,
    'primaryNote': primaryNote,
  };
  request({
    url: url,
    data: obj,
    type: "post",
    ajaxform: "true",
    callback: function(f) {
      if (f.code == 200) {
        ly.alert('保存成功', function() {
          window.location.reload();
        });
      } else {
        ly.toast(f.msg);
      }
    }
  });
}
